package com.ruoyi.project.business.salarydetail.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.salarydetail.entity.SalaryDetail;
import com.ruoyi.project.business.salarydetail.request.AddSalaryDetailRequest;
import com.ruoyi.project.business.salarydetail.request.ListSalaryDetailRequest;
import com.ruoyi.project.business.salarydetail.response.SalaryDetailResponse;
import com.ruoyi.project.business.salarydetail.service.ISalaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 薪资明细Controller
 * 
 * @author ${author}
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/business/salarydetail")
public class SalaryDetailController extends BaseController {
    @Autowired
    private ISalaryDetailService salaryDetailService;

    /**
     * 查询薪资明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:salarydetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListSalaryDetailRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<SalaryDetailResponse> list = salaryDetailService.selectSalaryDetailList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出薪资明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:salarydetail:export')")
    @Log(title = "薪资明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListSalaryDetailRequest request) {
        Long tenantId = getTenantId();
        List<SalaryDetailResponse> list = salaryDetailService.selectSalaryDetailList(request, tenantId);
        ExcelUtil<SalaryDetailResponse> util = new ExcelUtil<>(SalaryDetailResponse.class);
        return util.exportExcel(list, "salarydetail");
    }

    /**
     * 获取薪资明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:salarydetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(salaryDetailService.selectSalaryDetailById(id));
    }

    /**
     * 新增薪资明细
     */
    @PreAuthorize("@ss.hasPermi('business:salarydetail:add')")
    @Log(title = "薪资明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddSalaryDetailRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(salaryDetailService.insertSalaryDetail(request, operatorId, tenantId));
    }

    /**
     * 修改薪资明细
     */
    @PreAuthorize("@ss.hasPermi('business:salarydetail:edit')")
    @Log(title = "薪资明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalaryDetail salaryDetail) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(salaryDetailService.updateSalaryDetail(salaryDetail, operatorId, tenantId));
    }

    /**
     * 删除薪资明细
     */
    @PreAuthorize("@ss.hasPermi('business:salarydetail:remove')")
    @Log(title = "薪资明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(salaryDetailService.deleteSalaryDetailByIds(ids, operatorId, tenantId));
    }
}
